package com.itheima.web;

import com.itheima.dto.OrderInfoDto;
import com.itheima.entity.Result;
import com.itheima.service.OrderService;
import io.swagger.annotations.ApiOperation;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * company: www.abc.com
 * Author: 29746
 * Create Data: 2020/11/17
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private RabbitTemplate rabbitTemplate;
    @Reference
    private OrderService orderService;

    @GetMapping("/sendSmsCode/{telephone}")
    @ApiOperation("发送验证码")
    public void sendSmsCode(@PathVariable("telephone") String telephone){
        rabbitTemplate.convertAndSend("sms_exchange","sms",telephone);
    }



    @PostMapping("/add")
    @ApiOperation("立即预约")
    public Result add(@RequestBody OrderInfoDto orderInfoDto){
        return new Result(orderService.createOrder(orderInfoDto));
    }

    @GetMapping("/orderSuccess/{orderId}")
    @ApiOperation("预约成功")
    public Result orderSuccess(@PathVariable("orderId") String orderId){
        return new Result(orderService.orderSuccess(orderId));
    }

}
